package com.tajiang.business.setting.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.LinearLayout;

import com.google.gson.Gson;
import com.tajiang.business.R;
import com.tajiang.business.businesscount.wallet.ConfirmPsdActivity;
import com.tajiang.business.common.activity.BaseActivity;
import com.tajiang.business.common.http.BaseResponse;
import com.tajiang.business.common.http.HttpHandler;
import com.tajiang.business.common.http.HttpResponseListener;
import com.tajiang.business.common.utils.SharedPreferencesUtils;
import com.tajiang.business.model.User;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by SQL on 2016/6/25.
 */
public class PaySettingActivity extends BaseActivity implements HttpResponseListener {


    @BindView(R.id.ll_change_password)
    LinearLayout llChangePassword;
    @BindView(R.id.ll_find_password)
    LinearLayout llFindPassword;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_setting);
        ButterKnife.bind(this);
    }

    @Override
    protected void initTopBar() {
        setTitle(getResourcesString(R.string.msg_withdraw_setting));
    }

    @Override
    protected void initLayout() {

    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.ll_change_password)
    public void onChangePasswordClick() {
        String userStr = (String) SharedPreferencesUtils.get(SharedPreferencesUtils.USER_LOGIN_INFOR, "");
        User user = new Gson().fromJson(userStr,User.class);
        //请求判断用户是否设置过支付密码
        new HttpHandler(this).selctpsd(user.getUserId());
    }

    @OnClick(R.id.ll_find_password)
    public void onFindPasswordClick() {
        intent2Activity(FindPsdActivity.class);
    }


    @Override
    public void onSuccess(BaseResponse response) {
        Intent intent = new Intent();
        if ((Boolean)response.getData() == true) {  //设置过密码,需要进入输入原密码页面
            intent.putExtra("mode", ConfirmPsdActivity.STATE_MODE_HAVE_PAY_PWD);
            intent.setClass(PaySettingActivity.this, ChangePsdActivity.class);
        } else {                                //没有设置过密码，直接进入设置新密码页面
            intent.putExtra("mode", ConfirmPsdActivity.STATE_MODE_NO_PAY_PWD);
            intent.setClass(PaySettingActivity.this, ResetPsdActivity.class);
        }
        startActivity(intent);
        PaySettingActivity.this.finish();
    }

    @Override
    public void onFailed(BaseResponse response) {

    }

    @Override
    public void onFinish() {

    }
}
